package com.lanou3g.code0510;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dllo on 18/5/10.
 */
//Response Headers是发给浏览器的请求
@WebServlet(name = "BServlet", urlPatterns = "/b")
public class BServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response.setContentType("text/html;charset=utf-8");
        response.addHeader("Content-Type", "text/html;charset=utf-8");//添加头信息,发送请求给浏览器,表示这些文本信息都是utf-8进行编码
        //设置请求头,设置5秒后回到主页,定时刷新,我们不需要设置状态码,自动的,到时候就自己重定向过去了
        response.setHeader("Refresh", "5;URL=/index.jsp");
        /*
        setHeader与addHeader区别
        addHeader可以在响应头中一个key对应多个值
        setHeader不可以,key相同只会保留最后一个值
        setHeader用的比较多
         */
        response.getWriter().println("<a href=\"/index.jsp\">" +
                "5s后回到主页如果没有成功点击此处</a>");
        response.getWriter().println("同意");
    }
}
